package com.github.prontera.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @author Alex
 */
@Configuration
public class BeanConfiguration {

	@Bean
	public InitializationListener initializationListener() {
		return new InitializationListener();
	}
	
    private CorsConfiguration buildConfig() {  
        CorsConfiguration corsConfiguration = new CorsConfiguration();  
        corsConfiguration.addAllowedOrigin("*");  
        corsConfiguration.addAllowedHeader("*");  
        corsConfiguration.addAllowedMethod("*");  
        return corsConfiguration;  
    }  
      
    /** 
     * 跨域过滤器 
     */  
    @Bean  
    public CorsFilter corsFilter() {  
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();  
        source.registerCorsConfiguration("/**", buildConfig()); // 4  
        return new CorsFilter(source);  
    }  
	
//	@Bean
//	public MappingJackson2HttpMessageConverter initializationMappingJackson2Htt() {
//		System.out.println("---------------------------initializationMappingJackson2Htt---------------------------");
//		MappingJackson2HttpMessageConverter converter=new MappingJackson2HttpMessageConverter();
//		List<MediaType> supportedMediaTypes=new ArrayList<MediaType>();
//		supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
//		supportedMediaTypes.add(MediaType.TEXT_HTML);
//		supportedMediaTypes.add(MediaType.valueOf("text/json;charset=UTF-8"));
//		converter.setSupportedMediaTypes(supportedMediaTypes);
//		return converter;
//	}
	
	
}
